<!--面试考核-->
<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="table-body-box">
        <div class="hearder-search">
          <el-col :span="24" class="breadcrumb-container input-val-box">
            <el-button type="primary" size="small" @click="detailId=0,detailVisible=true">新增评测类</el-button>
            <el-button size="small" @click="InitFn"><i class="el-icon-refresh"></i>刷新</el-button>
            <span class="allbook">总 {{ page.total }} 条数据</span>
          </el-col>
        </div>
        <el-table
            ref="multipleTable"
            :data="arryList"
            :border="tableoption.tableBorder"
            tooltip-effect="dark">
          <el-table-column
              label="ID"
              align="center"
              width="100"
              prop="id">
          </el-table-column>
          <el-table-column
              label="评测类名"
              align="center"
              prop="name">
          </el-table-column>
          <el-table-column
              label="操作"
              align="center"
              width="260">
            <template slot-scope="scope">
              <el-button size="small" @click="listName=scope.row.name,listId=scope.row.id,listVisible=true" plain>评测项明细</el-button>
              <el-button size="small" @click="detailId=scope.row.id,detailVisible=true" type="primary" plain>编辑
              </el-button>
              <el-button size="small" @click="handleDetel(scope.row.id)" type="danger" plain>删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
      </el-col>
    </div>
    <detail :visible.sync="detailVisible" detailType="1" :detailId="detailId" @InitFn="InitFn"></detail>
    <list :visible.sync="listVisible" :listId="listId" :listName="listName"></list>
  </div>
</template>

<script>
import {pagination, tableoption, yeartime} from '@/utils/util.js'
import detail from "./detail";
import list from "./list";
import {assessCateIndex, assessCateDelete} from "@/api/admin/evaluating"

export default {
  components: {detail, list},
  data() {
    return {
      tableoption: tableoption,
      autosize: {minRows: 2, maxRows: 4},
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      detailVisible: false,
      detailType: '',
      detailId: 0,
      listVisible: false,
      listId: 0,
      listName: ''
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    addDevice() {

    },
    // 初始化
    async InitFn() {
      assessCateIndex({p: this.page.pageindex}).then(res => {
        if (!res.code) {
          for (let item of res.list.data) {
            item.eidt = false
          }
          this.arryList = res.list.data
          this.page.total = res.list.total
        }
      })
    },
    showEditFn(row, index) {
      let option = this.getJson(row)
      if (option.edit) {
        this.editTitle(option)
      } else {
        option.edit = true;
      }
      this.$set(this.arryList, index, option)
    },
    async editTitle(option) {
      let option_ = {
        id: option.id, // 	整型 	必填 	1 	- 	ID
        title: option.title, 	// 整型 	必填 	1 	- 	内容
        character_id: option.character_id, 	// 整型 	必填 	1 	- 	对应人格id
        user_title: option.user_title,
        parent_title: option.parent_title
      }
      let data = await this.$post(this.api.acquisition.setting.edit_personality, option_);
      if (!data.code) {
        option.edit = false;
      }
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    cateListFn() {
      this.$fetch(this.api.cate_list, {
        p: 1
      }).then((response) => {
        if (response.code === 0) {
          for (let i in response.list.data) {
            this.tableList.push(response.list.data[i])
          }
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    showDetail(id) {
      this.resumeId = id
      this.resumeVisible = true
    },
    handleClick(tab, event) {
      if (this.activeName !== this.activeNamechange) {
        this.activeNamechange = this.activeName;
        this.page.pageindex = 1
        this.arryList = []
        this.InitFn()
      }
    },
    // 获取岗位信息
    async JobFn() {
      let data = await this.$fetch(this.api.recruit.job.index, {p: 1});
      this.jobList = data.list.data;
    },
    searchFn(option) {
      if (option === 'refresh') {
        this.searchForm.name = ''
        this.searchForm.job_id = ''
      }
      this.page.pageindex = 1;
      this.InitFn()
    },
    handleDetel(id) {
      this.$confirm('确认永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(id)
      }).catch(() => {
      })
    }
    ,
    detelRespon(id) {
      assessCateDelete({id:id}).then(res=>{
        if(!res.code){
          this.$message(res.msg)
          this.InitFn()
        }
      })
    }
  },
  mounted() {
  }
}
</script>
<style>
.not-list {
  text-align: center;
  padding: 50px;
  color: #999;
  font-size: 16px;
}
</style>
